package com.pingan.haofang.searchcloud.web.monitor.controller;

import com.pingan.haofang.framework.common.functional.lang.control.bean.BeanCopy;
import com.pingan.haofang.searchcloud.common.constants.WebConstants;
import com.pingan.haofang.searchcloud.common.dto.PageDTO;
import com.pingan.haofang.searchcloud.common.dto.PageQueryDTO;
import com.pingan.haofang.searchcloud.common.form.PageForm;
import com.pingan.haofang.searchcloud.common.validator.annotation.Valid;
import com.pingan.haofang.searchcloud.monitor.dto.ChartReportResultDTO;
import com.pingan.haofang.searchcloud.monitor.dto.DashboardIndexSummaryInfoDTO;
import com.pingan.haofang.searchcloud.monitor.dto.DashboardIndexSummaryInfoQueryResult;
import com.pingan.haofang.searchcloud.monitor.service.DashboardIndexSummaryInfoService;
import com.pingan.haofang.searchcloud.web.monitor.form.DashboardIndexSummaryInfoForm;
import com.pingan.haofang.searchcloud.web.monitor.validator.DashboardMonitorValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(WebConstants.WEB_PREFIX + "/dashboardIndexSummaryInfo")
@Api(tags = "dashboard.index", description = "索引视图")
public class DashboardIndexSummaryInfoController {

    @Autowired
    private DashboardIndexSummaryInfoService dashboardIndexSummaryInfoService;

    @ApiOperation("索引视图-(列表分页)")
    @GetMapping("/indexViewByPage")
    @Valid(DashboardMonitorValidator.class)
    public PageDTO<DashboardIndexSummaryInfoQueryResult> indexViewByPage(DashboardIndexSummaryInfoForm parmForm,
                                                                         PageForm pageForm) {

        DashboardIndexSummaryInfoDTO parmDto =
                BeanCopy.toFunction(DashboardIndexSummaryInfoDTO.class, BeanUtils::copyProperties).apply(parmForm);

        PageQueryDTO pageQueryDTO =
                BeanCopy.toFunction(PageQueryDTO.class, BeanUtils::copyProperties).apply(pageForm);

        PageDTO<DashboardIndexSummaryInfoQueryResult> pageDTO = dashboardIndexSummaryInfoService.
                listPage(parmDto, pageQueryDTO);
        return pageDTO;
    }

    @ApiOperation("索引视图-(图表)")
    @GetMapping("/indexViewByChart")
    @Valid(DashboardMonitorValidator.class)
    public Map<String, ChartReportResultDTO> indexViewByChart(DashboardIndexSummaryInfoForm form) {

        DashboardIndexSummaryInfoDTO dto =
                BeanCopy.toFunction(DashboardIndexSummaryInfoDTO.class, BeanUtils::copyProperties).apply(form);

        Map<String, ChartReportResultDTO> resultDTOMap = dashboardIndexSummaryInfoService.indexViewByChart(dto);
        return resultDTOMap;
    }


    @ApiOperation("索引_选定项目视图-(列表分页)")
    @GetMapping("/indexViewByProjectOfPage")
    @Valid(DashboardMonitorValidator.class)
    public PageDTO<DashboardIndexSummaryInfoQueryResult> indexViewByProjectOfPage(DashboardIndexSummaryInfoForm parmForm,
                                                                                  PageForm pageForm) {
        DashboardIndexSummaryInfoDTO parmDto =
                BeanCopy.toFunction(DashboardIndexSummaryInfoDTO.class, BeanUtils::copyProperties).apply(parmForm);

        PageQueryDTO pageQueryDTO =
                BeanCopy.toFunction(PageQueryDTO.class, BeanUtils::copyProperties).apply(pageForm);

        PageDTO<DashboardIndexSummaryInfoQueryResult> pageDTO = dashboardIndexSummaryInfoService.
                indexViewByProjectOfPage(parmDto, pageQueryDTO);
        return pageDTO;
    }

    @ApiOperation("索引_选定项目视图-(图表)")
    @GetMapping("/indexViewByProjectOfChart")
    @Valid(DashboardMonitorValidator.class)
    public Map<String, ChartReportResultDTO> indexViewByProjectOfChart(DashboardIndexSummaryInfoForm form) {

        DashboardIndexSummaryInfoDTO dto =
                BeanCopy.toFunction(DashboardIndexSummaryInfoDTO.class, BeanUtils::copyProperties).apply(form);

        Map<String, ChartReportResultDTO> resultDTOMap = dashboardIndexSummaryInfoService.indexViewByChart(dto);
        return resultDTOMap;
    }

    @ApiOperation("索引_选定索引视图-(图表+列表分页)")
    @GetMapping("/indexViewByIndex")
    @Valid(DashboardMonitorValidator.class)
    public Map<String, Object> indexViewByIndex(DashboardIndexSummaryInfoForm form, PageForm pageForm) {

        DashboardIndexSummaryInfoDTO parmDto =
                BeanCopy.toFunction(DashboardIndexSummaryInfoDTO.class, BeanUtils::copyProperties).apply(form);

        PageQueryDTO pageQueryDto =
                BeanCopy.toFunction(PageQueryDTO.class, BeanUtils::copyProperties).apply(pageForm);

        Map<String, Object> resultDTOMap = dashboardIndexSummaryInfoService.indexViewByIndex(parmDto, pageQueryDto);
        return resultDTOMap;
    }
}
